package com.nextel.project.agps;

import javax.microedition.lcdui.CustomItem;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

public class IndicadorGPS extends CustomItem {
    //private int alto = 26;
    private int alto = 16;
    private int ancho = 300;
    private int colorSenal = 0x00ff0000;
    private int colorTiempo = 0x0000ff00;
    private int colorTexto = 0x00000000;
    //private Font fuente = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
    private Font fuente = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    private String textoSenal = "SE:";
    private String textoTiempo = "TI:";
    //private final int anchoLed = 20, altoLed = 20;
    private final int anchoLed = 10,  altoLed = 10;
    //private final int espacioLeds = 15;
    private final int espacioLeds = 20;

    public IndicadorGPS() {
        super(null);
    }

    protected int getPrefContentWidth(int height) {
        return ancho;
    }

    protected int getPrefContentHeight(int width) {
        return alto;
    }

    protected boolean traverse(int dir,
            int viewportWidth,
            int viewportHeight,
            int[] visRect_inout) {
        
        
        if (visRect_inout[3] < getPreferredHeight()) {
            visRect_inout[3] = getPreferredHeight();
        }
        
        if (visRect_inout[1] > 0) {
            visRect_inout[1] = 0;
        }
        
        if (dir == NONE) {
            return true;
        } else {
            repaint();
            return false;
        }
    }

    protected void paint(Graphics graphics, int w, int h) {
        //int x = 5;
        int x = 15;
        //int y = 3;
        int y = 2;
        graphics.setFont(fuente);

        graphics.setColor(colorTexto);
        graphics.drawString(textoSenal, x, (alto - fuente.getHeight()) / 2, Graphics.TOP | Graphics.LEFT);

        x += fuente.stringWidth(textoSenal) + 2;

        graphics.setColor(colorSenal);
        graphics.fillArc(x, y, anchoLed, altoLed, 0, 360);

        x += anchoLed + espacioLeds;

        graphics.setColor(colorTexto);
        graphics.drawString(textoTiempo, x, (alto - fuente.getHeight()) / 2, Graphics.TOP | Graphics.LEFT);

        x += fuente.stringWidth(textoTiempo) + 2;

        graphics.setColor(colorTiempo);
        graphics.fillArc(x, y, anchoLed, altoLed, 0, 360);
    }

    protected int getMinContentWidth() {
        return ancho;
    }

    protected int getMinContentHeight() {
        return alto;
    }

    public int getColorSenal() {
        return colorSenal;
    }

    public void setColorSenal(int colorSenal) {
        this.colorSenal = colorSenal;
        repaint();
    }

    public int getColorTiempo() {
        return colorTiempo;
    }

    public void setColorTiempo(int colorTiempo) {
        this.colorTiempo = colorTiempo;
        repaint();
    }
}
